/****************************************************************************************************************************************************************
 *                                                                                                                                                              *
 *                                                                                                                                                              *
 *                                                                                                                                                              *
 *                                                                                                                                                              *
 *                      _____  ___________                   ___    ______      ______           _____     _______________________                              *
 *                      __  / / /__  /_  /_____________ _    __ |  / /__(_)________  /_____________  /_    ___    |_____/_/__  __ \                             *
 *                      _  / / /__  /_  __/_  ___/  __ `/    __ | / /__  /_  __ \_  /_  _ \_  __ \  __/    __  /| |___/_/ __  / / /                             *
 *                      / /_/ / _  / / /_ _  /   / /_/ /     __ |/ / _  / / /_/ /  / /  __/  / / / /_      _  ___ |_/_/   _  /_/ /                              *
 *                      \____/  /_/  \__/ /_/    \__,_/      _____/  /_/  \____//_/  \___//_/ /_/\__/      /_/  |_/_/     /_____/                               *
 *                                                                                                                                                              *
 *                                                                                                                                                              *
 *                                                                                                                                                              *
 *                                                                                                                                                              *
 *                                                                                                                                                              *
 *      @Project: Ultra Violent - Attack and Defend                                                                                                             *
 *                                                                                                                                                              *
 *                                                                                                                                                              *
 *      @Author: Daniel "thiaZ" Koenen                                                                                                                          *
 *          @Used content                                                                                                                                       *
 *              @sscanf Plugin, foreach, Whirlpool Plugin, YSI - Y_Less                                                                                         *
 *              @zcmd - Zeex                                                                                                                                    *
 *              @Streamer Plugin, IRC Plugin - Incognito                                                                                                        *
 *              @dini - Dracoblue                                                                                                                               *
 *              @MySQL Plugin - G-sTyLeZzZ                                                                                                                      *
 *          @Special thanks to                                                                                                                                  *
 *              @Slice                                                                                                                                          *
 *                                                                                                                                                              *
 *                                                                                                                                                              *
 *      @File: uvaad.pwn - Main File                                                                                                                            *
 *                                                                                                                                                              *
 *                                                                                                                                                              *
 *      @This file is not released under any open source licence, you are not allowed to own this file except you have the author's permission.                 *
 *                                                                                                                                                              *
 *                                                                                                                                                              *
 *      @copyright (c) Daniel "thiaZ" Koenen 2010 - 2011 - danielkoenen@t-online.de                                                                             *
 *                                                                                                                                                              *
 ****************************************************************************************************************************************************************/          
#if DEBUG
cmd(vbring, playerid, params[])
{
    if(!IsPlayerAdmin(playerid))
    {
        return false;
    }
    
    new iVehicle,
        iVID,
        ipInterior,
        Float:fX,
        Float:fY,
        Float:fZ,
        Float:fA;
        
    if(sscanf(params, "d", iVehicle))
    {
        return false;
    }
    
    GetPlayerPos(playerid, fX, fY, fZ);
    ipInterior = GetPlayerVirtualWorld(playerid);
    
    iVID = CreateVehicle(iVehicle, fX, fY, fZ, fA, 0, 0, 60);
    SetVehicleVirtualWorld(iVID, ipInterior);
    PutPlayerInVehicle(playerid, iVID, 0);
    return true;
}

cmd(savepos, playerid, params[]) 
{
    if(playerData[playerid][level] < LEVEL_MANAGEMENT) 
    {
        return false;
    }
    
    new Comment[16];
    if(sscanf(params, "s[32]", Comment)) 
    {
        return false;
    }
    
    CPlayer::savePos(playerid, Comment);
    return true;
}

cmd(saveveh, playerid, params[]) 
{
    if(playerData[playerid][level] < LEVEL_MANAGEMENT) 
    {
        return false;
    }
    
    new Comment[16];
    if(sscanf(params, "s[32]", Comment)) 
    {
        return false;
    }
    
    if(!IsPlayerInAnyVehicle(playerid)) 
    {
        return false;
    }
    
    CPlayer::savevPos(playerid, Comment);
    return true;
}

cmd(jetpack, playerid, params[]) 
{
    if(playerData[playerid][level] < LEVEL_MANAGEMENT) 
    {
        return false;
    }
    
    SetPlayerSpecialAction(playerid, SPECIAL_ACTION_USEJETPACK);
    SendClientMessage(playerid, C_GREEN, "* Spawned a jetpack, have fun.");
    return true;
}


cmd(showbases, playerid, params[])
{
    if(playerData[playerid][level] < LEVEL_MANAGEMENT) 
    {
        return false;
    }
    
    CCreation::showBases();
    SendClientMessageToAll(C_YELLOW, "* Base Creation System loaded.");
    return true;
}

cmd(hidebases, playerid, params[])
{
    if(playerData[playerid][level] < LEVEL_MANAGEMENT) 
    {
        return false;
    }
    
    CCreation::destroyBases();
    SendClientMessageToAll(C_YELLOW, "* Base Creation System unloaded.");
    return true;
}

cmd(base, playerid, params[])
{
    if(playerData[playerid][level] < LEVEL_MANAGEMENT) 
    {
        return false;
    }
    
    CCreation::showBaseDialog(playerid, DIALOG_CHOOSE);
    return true;
}

cmd(createbase, playerid, params[])
{
    if(playerData[playerid][level] < LEVEL_MANAGEMENT) 
    {
        return false;
    }
    
    CCreation::showBaseDialog(playerid, DIALOG_CREATE);
    return true;
}
#endif

cmd(mute, playerid, params[])
{
    if(playerData[playerid][level] < LEVEL_MOD) 
    {
        return false;
    }
    
    new iPlayer,
        szReason[64];
        
    if(sscanf(params, "us[64]", iPlayer, szReason)) 
    {
        SendClientMessage(playerid, C_RED, "* Syntax Error: '/mute <PlayerID/Name> <Reason>'");
        return true;
    }
    
    if(!IsPlayerConnected(iPlayer)) 
    {
        SendClientMessage(playerid, C_RED, "* Error: Invalid player!");
        return true;
    }
    
    playerData[iPlayer][isMuted] = true;
    SendFormattedMessage(iPlayer, C_YELLOW, "You have been temporary muted by %s. (%s)", CPlayer::getName(playerid), szReason);
    SendClientMessage(playerid, C_YELLOW, "* Player has been muted.");
    return true;
}

cmd(muteall, playerid, params[])
{
    if(playerData[playerid][level] < LEVEL_MOD) 
    {
        return false;
    }
    
    loop_players(iPlayer)
    {
        if(playerid == iPlayer)
        {
            continue;
        }
        
        playerData[iPlayer][isMuted] = true;
        SendFormattedMessage(iPlayer, C_YELLOW, "You have been temporary muted by %s. (Important announcement)", CPlayer::getName(playerid));
    }
    
    SendClientMessage(playerid, C_YELLOW, "* All players have been muted, don't forget to unmute them once you are done.");
    return true;
}

cmd(unmuteall, playerid, params[])
{
    if(playerData[playerid][level] < LEVEL_MOD) 
    {
        return false;
    }
    
    loop_players(iPlayer)
    {
        if(playerid == iPlayer)
        {
            continue;
        }
        
        playerData[iPlayer][isMuted] = false;
        SendFormattedMessage(iPlayer, C_YELLOW, "You have been temporary unmuted by %s.", CPlayer::getName(playerid));
    }
    
    SendClientMessage(playerid, C_YELLOW, "* All players have been unmuted.");
    return true;
}
    
cmd(unmute, playerid, params[])
{
    if(playerData[playerid][level] < LEVEL_MOD) 
    {
        return false;
    }
    
    new iPlayer;
        
    if(sscanf(params, "u", iPlayer)) 
    {
        SendClientMessage(playerid, C_RED, "* Syntax Error: '/unmute <PlayerID/Name>'");
        return true;
    }
    
    if(!IsPlayerConnected(iPlayer)) 
    {
        SendClientMessage(playerid, C_RED, "* Error: Invalid player!");
        return true;
    }
    
    playerData[iPlayer][isMuted] = false;
    SendFormattedMessage(iPlayer, C_YELLOW, "You have been unmuted by %s.", CPlayer::getName(playerid));
    SendClientMessage(playerid, C_YELLOW, "* Player has been unmuted.");
    return true;
}

cmd(slap, playerid, params[])
{
    if(playerData[playerid][level] < LEVEL_MOD) 
    {
        return false;
    }   
    
    new iPlayer, iHeight;
    if(sscanf(params, "ud", iPlayer, iHeight))
    {
        SendClientMessage(playerid, C_RED, "* Syntax Error: '/slap <PlayerID/Name> <Height>'");
        return true;
    }   

    if(!IsPlayerConnected(iPlayer))
    {
        SendClientMessage(playerid, C_RED, "* Error: Invalid player.");
        return true;
    }
    
    new Float:X,
        Float:Y,
        Float:Z;
        
    GetPlayerPos(iPlayer, X, Y, Z);
    SetPlayerPos(iPlayer, X, Y, Z + float(iHeight));
    
    SendFormattedMessageToAll(C_YELLOW, "* %s slapped %s.", CPlayer::getName(playerid), CPlayer::getName(iPlayer));
    return true;
}

cmd(explode, playerid, params[])
{
    if(playerData[playerid][level] < LEVEL_MOD) 
    {
        return false;
    }   
    
    new iPlayer;
    if(sscanf(params, "u", iPlayer))
    {
        SendClientMessage(playerid, C_RED, "* Syntax Error: '/explode <PlayerID/Name>'");
        return true;
    }   

    if(!IsPlayerConnected(iPlayer))
    {
        SendClientMessage(playerid, C_RED, "* Error: Invalid player.");
        return true;
    }
    
    new Float:X,
        Float:Y,
        Float:Z;
        
    GetPlayerPos(iPlayer, X, Y, Z);
    CreateExplosion(X, Y, Z, 6, 10.0);
    SetPlayerHealth(iPlayer, 0.0);
    
    SendFormattedMessageToAll(C_YELLOW, "* %s exploded %s.", CPlayer::getName(playerid), CPlayer::getName(iPlayer));
    return true;
}


cmd(fspawn, playerid, params[])
{
    if(playerData[playerid][level] < LEVEL_MOD) 
    {
        return false;
    }   
    
    new iPlayer;
    if(sscanf(params, "u", iPlayer))
    {
        SendClientMessage(playerid, C_RED, "* Syntax Error: '/fspawn <PlayerID/Name>'");
        return true;
    }   

    if(!IsPlayerConnected(iPlayer))
    {
        SendClientMessage(playerid, C_RED, "* Error: Invalid player.");
        return true;
    }
    
    playerData[iPlayer][isDMSpawn] = false;
    playerData[iPlayer][isPlaying] = false;
    CPlayer::SpawnEx(iPlayer);
    
    SendFormattedMessageToAll(C_YELLOW, "* %s brought %s to the lobby.", CPlayer::getName(playerid), CPlayer::getName(iPlayer));
    return true;
}

cmd(setscore, playerid, params[])
{
    if(playerData[playerid][level] < LEVEL_ADMIN) 
    {
        return false;
    }
    
    new _iTeam,
        _iScore;
        
    if(sscanf(params, "dd", _iTeam, _iScore))
    {
        SendClientMessage(playerid, C_RED, "* Syntax Error: '/setscore <TeamID> <Score>'");
        SendClientMessage(playerid, C_RED, "* Team IDs: Team Home 0, Team Away 1");
        return true;
    }
    
    if(_iTeam < 0 || _iTeam > 1)
    {
        SendClientMessage(playerid, C_RED, "* Syntax Error: '/setscore <TeamID> <Score>'");
        SendClientMessage(playerid, C_RED, "* Team IDs: Team Home 0, Team Away 1");
        return true;
    }
    
    teamData[_iTeam][iTeamScore] = _iScore;
    
    if(_iTeam == 0)
    {
        SendFormattedMessageToAll(C_GOLD, "* %s has changed Team Home's team score to %d.", CPlayer::getName(playerid), _iScore);
    }
    
    else
    {
        SendFormattedMessageToAll(C_GOLD, "* %s has changed Team Away's team score to %d.", CPlayer::getName(playerid), _iScore);
    }
    
    return true;
}
    
    

cmd(aka, playerid, params[])
{
    if(playerData[playerid][level] < LEVEL_ADMIN) 
    {
        return false;
    }
    
    new iPlayer;
    if(sscanf(params, "u", iPlayer))
    {
        SendClientMessage(playerid, C_RED, "* Syntax Error: '/aka <PlayerID/Name>'");
        return true;
    }
    
    if(!playerData[iPlayer][isSpawned])
    {
        SendClientMessage(playerid, C_RED, "* Error: The player has to spawn first.");
        return true;
    }
    
    new szQuery[128],
        szName[MAX_PLAYER_NAME],
        szOutput[128];
        
    format(szQuery, 128, "SELECT username FROM players WHERE ipadress = '%s'", CPlayer::getIP(iPlayer));
    mysql_query(szQuery);
    mysql_store_result();
    
    if(!mysql_num_rows())
    {
        SendClientMessage(playerid, C_RED, "* Error: Could not get names.");
        mysql_free_result();
        return true;
    }
        
    format(szOutput, 128, "Names with IP address %s: ", CPlayer::getIP(iPlayer));
    while(mysql_retrieve_row())
    {
        if(strlen(szOutput) <= 100)
        {
            mysql_get_field("username", szName);
            format(szOutput, 128, "%s%s, ", szOutput, szName);
        }
            
        else
        {
            SendClientMessage(playerid, C_YELLOW, szOutput);
            format(szOutput, 128, "");
        }
    }
        
    if(strlen(szOutput) > 4)
    {
        strdel(szOutput, strlen(szOutput) - 2, strlen(szOutput));
        SendClientMessage(playerid, C_YELLOW, szOutput);
    }
    
    mysql_free_result();
    return true;
}              

cmd(fkill, playerid, params[])
{
    if(playerData[playerid][level] < LEVEL_MOD) 
    {
        return false;
    }   
    
    new iPlayer;
    if(sscanf(params, "d", iPlayer))
    {
        SendClientMessage(playerid, C_RED, "* Syntax Error: '/fkill <PlayerID/Name>'");
        return true;
    }   

    if(!IsPlayerConnected(iPlayer))
    {
        SendClientMessage(playerid, C_RED, "* Error: Invalid player.");
        return true;
    }
    
    SetPlayerHealth(iPlayer, 0.0);
    
    SendFormattedMessageToAll(C_YELLOW, "* %s killed %s using commands.", CPlayer::getName(playerid), CPlayer::getName(iPlayer));
    return true;
}

cmd(heal, playerid, params[])
{
    if(playerData[playerid][level] < LEVEL_MOD) 
    {
        return false;
    }   
    
    new iPlayer;
    if(sscanf(params, "d", iPlayer))
    {
        SendClientMessage(playerid, C_RED, "* Syntax Error: '/heal <PlayerID/Name>'");
        return true;
    }   

    if(!IsPlayerConnected(iPlayer))
    {
        SendClientMessage(playerid, C_RED, "* Error: Invalid player.");
        return true;
    }
    
    SetPlayerHealth(iPlayer, 100.0);
    SetPlayerArmour(iPlayer, 100.0);
    
    SendFormattedMessageToAll(C_YELLOW, "* %s healed %s.", CPlayer::getName(playerid), CPlayer::getName(iPlayer));
    return true;
}

cmd(fspawnall, playerid, params[])
{
    if(playerData[playerid][level] < LEVEL_MOD) 
    {
        return false;
    }   
    
    loop_players(iPlayer)
    {
        playerData[iPlayer][isDMSpawn] = false;
        playerData[iPlayer][isPlaying] = false;
        CPlayer::SpawnEx(iPlayer);
    }
    
    SendFormattedMessageToAll(C_YELLOW, "* %s brought all players to the lobby.", CPlayer::getName(playerid));
    return true;
}

cmd(kick, playerid, params[]) 
{
    if(playerData[playerid][level] < LEVEL_MOD) 
    {
        return false;
    }
    
    new iKickPlayerID,
        szReason[64];
        
    if(sscanf(params, "us[64]", iKickPlayerID, szReason)) 
    {
        SendClientMessage(playerid, C_RED, "* Syntax Error: '/kick <PlayerID/Name> <Reason>'");
        return true;
    }
    
    if(!IsPlayerConnected(iKickPlayerID)) 
    {
        SendClientMessage(playerid, C_RED, "* Error: Invalid player!");
        return true;
    }
    
    if(playerData[playerid][level] <= playerData[iKickPlayerID][level])
    {
        SendClientMessage(playerid, C_RED, "* Error: You can't ban players with a higher adminlevel than yours.");
        return true;
    }
    
    CPlayer::KickEx(iKickPlayerID, CPlayer::getName(playerid), szReason, false);
    SendClientMessage(playerid, C_YELLOW, "* Player has been kicked.");
    return true;
}

cmd(swap, playerid, params[]) 
{
    if(playerData[playerid][level] < LEVEL_MOD) 
    {
        return false;
    }
    
    if(teamData[TEAM_HOME][bAttacking] == true)
    {
        teamData[TEAM_HOME][bAttacking] = false;
        teamData[TEAM_AWAY][bAttacking] = true;
    }
    
    if(teamData[TEAM_HOME][bAttacking] == false)
    {
        teamData[TEAM_HOME][bAttacking] = true;
        teamData[TEAM_AWAY][bAttacking] = false;
    }
    
    loop_players(iPlayer)
    {
        CPlayer::UpdatePlayerColor(iPlayer);
    }
    
    SendFormattedMessageToAll(C_GOLD, "* %s swapped the team roles.", CPlayer::getName(playerid));
    return true;
}
    
cmd(ban, playerid, params[]) 
{
    if(playerData[playerid][level] < LEVEL_ADMIN) 
    {
        return false;
    }
    
    new iKickPlayerID,
        szReason[64];
        
    if(sscanf(params, "us[64]", iKickPlayerID, szReason)) 
    {
        SendClientMessage(playerid, C_RED, "* Syntax Error: '/ban <PlayerID/Name> <Reason>'");
        return true;
    }
    
    if(!IsPlayerConnected(iKickPlayerID)) 
    {
        SendClientMessage(playerid, C_RED, "* Error: Invalid player!");
        return true;
    }
    
    if(playerData[playerid][level] <= playerData[iKickPlayerID][level])
    {
        SendClientMessage(playerid, C_RED, "* Error: You can't ban players with a higher adminlevel than yours.");
        return true;
    }
    
    CPlayer::KickEx(iKickPlayerID, CPlayer::getName(playerid), szReason, true);
    SendClientMessage(playerid, C_YELLOW, "* Player has been banned.");
    return true;
}

cmd(unban, playerid, params[])
{
    if(playerData[playerid][level] < LEVEL_ADMIN) 
    {
        return false;
    }
    
    new szPlayer[30],
        szEscape[30],
        szQuery[128],
        iQuery;
        
    if(sscanf(params, "s[30]", szPlayer)) 
    {
        SendClientMessage(playerid, C_RED, "* Syntax Error: '/unban <Exact player name>'");
        return true;
    }
    
    mysql_real_escape_string(szPlayer, szEscape);
    format(szQuery, 128, "SELECT banned FROM players WHERE username = '%s'", szEscape);
    iQuery = mysql_query(szQuery);
    
    if(!iQuery)
    {
        SendClientMessage(playerid, C_RED, "* Database error: Ask thiaZ for support.");
        return true;
    }
    
    mysql_store_result();
    if(!mysql_num_rows())
    {
        SendClientMessage(playerid, C_RED, "* Error: No results, be sure to type the exact name.");
        mysql_free_result();
        return true;
    }
    
    new szResult[5];
    mysql_fetch_row_format(szResult);
    
    if(!strval(szResult))
    {
        SendClientMessage(playerid, C_RED, "* Error: This player was not banned.");
        mysql_free_result();
        return true;
    }
    
    format(szQuery, 128, "UPDATE players SET banned = 0 WHERE username = '%s'", szEscape);
    iQuery = mysql_query(szQuery);
    
    if(!iQuery)
    {   
        SendClientMessage(playerid, C_RED, "* Database error: Could not unban player, report this to thiaZ.");
        return true;
    }
    
    SendFormattedMessage(playerid, C_GREEN, "* %s has been unbanned.", szPlayer);
    return true;
}

cmd(setlevel, playerid, params[]) 
{
    if(!IsPlayerAdmin(playerid)) 
    {
        return false;
    }
    
    new iPlayer,
        iLevel;
        
    if(sscanf(params, "ud", iPlayer, iLevel)) 
    {
        SendClientMessage(playerid, C_RED, "* Syntax Error: '/setlevel <PlayerID/Name> <0-3>'");
        return true;
    }
    
    if(iLevel > 3 || iLevel < 0)
    {
        SendClientMessage(playerid, C_RED, "* Syntax Error: '/setlevel <PlayerID/Name> <0-3>'");
        return true;
    }
    
    if(!IsPlayerConnected(playerid)) 
    {
        SendClientMessage(playerid, C_RED, "* Error: Invalid player.");
        return true;
    }
    
    playerData[iPlayer][level] = iLevel;
    SendFormattedMessage(playerid, C_YELLOW, "* You updated %s's adminlevel to level %s.", CPlayer::getName(iPlayer), CPlayer::getLevelName(iPlayer));
    SendFormattedMessage(iPlayer, C_YELLOW, "* %s's updated your adminlevel to level %s.", CPlayer::getName(playerid), CPlayer::getLevelName(iPlayer));
    return true;
}

cmd(config, playerid, params[]) 
{
    if(playerData[playerid][level] < LEVEL_ADMIN) 
    {
        return false;
    }
    
    if(gameData[bIsRoundActive] == true)
    {
        SendClientMessage(playerid, C_RED, "* Error: You can't change config values while a base is active.");
        return true;
    }

    CConfig::showDialog(playerid, DIALOG_CONFIG_MAIN);
    return true;
}

cmd(fsync, playerid, params[]) {
    if(playerData[playerid][level] < LEVEL_MOD) {
        return true;
    }
    
    new iPlayer;
    
    if(sscanf(params, "u", iPlayer)) {
        SendClientMessage(playerid, C_RED, "* Syntax Error: '/fsync <PlayerID/Name>'");
        return true;
    }
    
    if(!IsPlayerConnected(iPlayer)) {
        SendClientMessage(playerid, C_RED, "* Error: Invalid player.");
        return true;
    }
    
    SendClientMessage(iPlayer, C_YELLOW, "* Synchronizing...");
    alias_Sync(iPlayer);
    SendClientMessage(playerid, C_YELLOW, "* The player has been synchronized.");
    return true;
}

cmd(sethealth, playerid, params[]) {
    if(playerData[playerid][level] < LEVEL_MOD) {
        return false;
    }
    
    new iPlayer,
        iHealth;
        
    if(sscanf(params, "ud", iPlayer, iHealth)) {
        SendClientMessage(playerid, C_RED, "* Syntax Error: '/sethealth <PlayerID/Name> <0-200>'");
        return true;
    }
    
    if(iHealth > 200 || iHealth < 0) {
        SendClientMessage(playerid, C_RED, "* Syntax Error: '/sethealth <PlayerID/Name> <0-200>'");
        return true;
    }
    
    if(iHealth <= 100) {
        SetPlayerHealth(iPlayer, float(iHealth));
        SetPlayerArmour(iPlayer, 0.0);
    }
    
    if(iHealth > 100) {
        SetPlayerHealth(iPlayer, 100.0);
        SetPlayerArmour(iPlayer, float(iHealth - 100));
    }
        
    SendFormattedMessageToAll(C_GOLD, "* %s changed %s health to %d.", CPlayer::getName(playerid), CPlayer::getName(iPlayer), iHealth);
    return true;
}

cmd(fswitch, playerid, params[]) {
    if(playerData[playerid][level] < LEVEL_MOD) 
    {
        return false;
    }
    
    new iPlayer,
        isTeam;
        
    if(sscanf(params, "ud", iPlayer, isTeam)) 
    {
        SendClientMessage(playerid, C_RED, "* Syntax Error: '/fswitch <PlayerID/Name> <TeamID>'");
        SendClientMessage(playerid, C_RED, "* TeamIDs: 0 HOME / 1 AWAY / 2 REFEREE / 3 HOME SUB / 4 AWAY SUB");
        return true;
    }
    
    if(gameData[bIsRoundActive] == true && playerData[iPlayer][isPlaying] == true) 
    {
        SendClientMessage(playerid, C_RED, "* Error: You can't switch someones team while the round is active, got it?");
        return true;
    }
    
    switch(isTeam) 
    {
        case TEAM_HOME: 
        {
            CPlayer::crashSafeSkinSync(iPlayer, gameConfig[teamSkin][TEAM_HOME]);
            
            playerData[iPlayer][team] = TEAM_HOME;
            CPlayer::UpdatePlayerColor(iPlayer);
            if(teamData[TEAM_HOME][bAttacking] == true) 
            {
                SendFormattedMessageToAll(C_ATT, "* %s has been switched to team %s. (Attacking)", CPlayer::getName(iPlayer), gameConfig[homeName]);
            }
                    
            else 
            {
                SendFormattedMessageToAll(C_DEF, "* %s has been switched to team %s. (Defending)", CPlayer::getName(iPlayer), gameConfig[homeName]);
            }
        }
        
        case TEAM_AWAY: 
        {
            CPlayer::crashSafeSkinSync(iPlayer, gameConfig[teamSkin][TEAM_AWAY]);
            
            playerData[iPlayer][team] = TEAM_AWAY;
            CPlayer::UpdatePlayerColor(iPlayer);
            if(teamData[TEAM_AWAY][bAttacking] == true) 
            {
                SendFormattedMessageToAll(C_ATT, "* %s has been switched to team %s. (Attacking)", CPlayer::getName(iPlayer), gameConfig[awayName]);
            }
                    
            else 
            {
                SendFormattedMessageToAll(C_DEF, "* %s has been switched to team %s. (Defending)", CPlayer::getName(iPlayer), gameConfig[awayName]);
            }
        }
        
        case TEAM_REF: 
        {
            CPlayer::crashSafeSkinSync(iPlayer, gameConfig[teamSkin][TEAM_AWAY]);
            
            playerData[iPlayer][team] = TEAM_REF;
            CPlayer::UpdatePlayerColor(iPlayer);
                    
            SendFormattedMessageToAll(C_YELLOW, "* %s has been switched to team Referee.", CPlayer::getName(iPlayer));
        }
        
        case TEAM_HOME_SUB: 
        {
            CPlayer::crashSafeSkinSync(iPlayer, gameConfig[teamSkin][TEAM_HOME]);
            
            playerData[iPlayer][team] = TEAM_HOME_SUB;
            CPlayer::UpdatePlayerColor(iPlayer);
            if(teamData[TEAM_HOME][bAttacking] == true) 
            {
                SendFormattedMessageToAll(C_ATT, "* %s has been switched to substitute for team %s. (Attacking)", CPlayer::getName(iPlayer), gameConfig[homeName]);
            }
                    
            else 
            {
                SendFormattedMessageToAll(C_DEF, "* %s has been switched to substitute for team %s. (Defending)", CPlayer::getName(iPlayer), gameConfig[homeName]);
            }
        }
                
        case TEAM_AWAY_SUB: 
        {
            CPlayer::crashSafeSkinSync(iPlayer, gameConfig[teamSkin][TEAM_AWAY]);
            
            playerData[iPlayer][team] = TEAM_AWAY_SUB;
            CPlayer::UpdatePlayerColor(iPlayer);
            if(teamData[TEAM_AWAY][bAttacking] == true) 
            {
                SendFormattedMessageToAll(C_ATT, "* %s has been switched to substitute for team %s. (Attacking)", CPlayer::getName(iPlayer), gameConfig[awayName]);
            }
                    
            else 
            {
                SendFormattedMessageToAll(C_DEF, "* %s has been switched to substitute for team %s. (Defending)", CPlayer::getName(iPlayer), gameConfig[awayName]);
            }
        }
        
        default: 
        {
            SendClientMessage(playerid, C_RED, "* Syntax Error: '/fswitch <PlayerID/Name> <TeamID>'");
            SendClientMessage(playerid, C_RED, "* TeamIDs: 0 HOME / 1 AWAY / 2 REFEREE / 3 HOME SUB / 4 AWAY SUB");
            return true;
        }
    }
    
    return true;
}

cmd(goto, playerid, params[]) 
{
    if(playerData[playerid][level] < LEVEL_MOD) 
    {
        return false;
    }
    
    new iPlayer;
    
    if(sscanf(params, "u", iPlayer)) 
    {
        SendClientMessage(playerid, C_RED, "* Syntax Error: '/goto <PlayerID/Name>'");
        return true;
    }
    
    if(!IsPlayerConnected(iPlayer) || playerid == iPlayer) 
    {
        SendClientMessage(playerid, C_RED, "* Error: Invalid player!");
        return true;
    }
    
    if(playerData[iPlayer][isSpawned] == false || playerData[iPlayer][isPlaying] == true || playerData[iPlayer][activeDM] > -1) 
    {
        SendClientMessage(playerid, C_YELLOW, "* Error: You can't teleport to this player right now!");
        return true;
    }
    
    new Float:X,
        Float:Y,
        Float:Z,
        Float:A;
        
    GetPlayerPos(iPlayer, X, Y, Z);
    GetPlayerFacingAngle(iPlayer, A);
    
    if(!IsPlayerInAnyVehicle(playerid)) 
    {
        SetPlayerPos(playerid, X, Y, Z);
        SetPlayerFacingAngle(playerid, A);
        SetCameraBehindPlayer(playerid);
    }
    
    else 
    {
        new vID = GetPlayerVehicleID(playerid);
        SetVehiclePos(vID, X, Y, Z);
        SetVehicleZAngle(vID, A);
        SetCameraBehindPlayer(playerid);
    }
    
    SendFormattedMessage(playerid, C_PINK, "* You've been teleported to %s.", CPlayer::getName(iPlayer));
    SendFormattedMessage(iPlayer, C_PINK, "* %s has been teleported to you.", CPlayer::getName(playerid));
    return true;
}

cmd(gethere, playerid, params[]) {
    if(playerData[playerid][level] < LEVEL_MOD) {
        return false;
    }
    
    new iPlayer;
    
    if(sscanf(params, "u", iPlayer)) {
        SendClientMessage(playerid, C_RED, "* Syntax Error: '/gethere <PlayerID/Name>'");
        return true;
    }
    
    if(!IsPlayerConnected(iPlayer) || playerid == iPlayer) {
        SendClientMessage(playerid, C_RED, "* Error: Invalid player!");
        return true;
    }
    
    if(playerData[iPlayer][isSpawned] == false || playerData[iPlayer][isPlaying] == true || playerData[iPlayer][activeDM] > -1) 
    {
        SendClientMessage(playerid, C_YELLOW, "* Error: You can't teleport this player to you right now!");
        return true;
    }
    
    new Float:X,
        Float:Y,
        Float:Z,
        Float:A;
        
    GetPlayerPos(playerid, X, Y, Z);
    GetPlayerFacingAngle(playerid, A);
    
    if(!IsPlayerInAnyVehicle(iPlayer)) {
        SetPlayerPos(iPlayer, X, Y, Z);
        SetPlayerFacingAngle(iPlayer, A);
        SetCameraBehindPlayer(iPlayer);
    }
    
    else {
        new vID = GetPlayerVehicleID(iPlayer);
        SetVehiclePos(vID, X, Y, Z);
        SetVehicleZAngle(vID, A);
        SetCameraBehindPlayer(iPlayer);
    }
    
    SendFormattedMessage(iPlayer, C_PINK, "* You've been teleported to %s.", CPlayer::getName(playerid));
    SendFormattedMessage(playerid, C_PINK, "* %s has been teleported to you.", CPlayer::getName(iPlayer));
    return true;
}

cmd(give, playerid, params[]) {
    if(playerData[playerid][level] < LEVEL_MOD) {
        return false;
    }
    
    new iPlayer;
    
    if(sscanf(params, "u", iPlayer)) {
        SendClientMessage(playerid, C_RED, "* Syntax Error: '/give <PlayerID/Name>'");
        return true;
    }
    
    if(!IsPlayerConnected(iPlayer)) {
        SendClientMessage(playerid, C_RED, "* Error: Invalid player!");
        return true;
    }
    
    if(playerData[iPlayer][isPlaying] == true) {
        
        new igTeam = playerData[iPlayer][team],
            iAmmo,
            igWeapons[12];
                
        for(new i; i < 12; i++) {
            GetPlayerWeaponData(iPlayer, i, igWeapons[i], iAmmo);
            if(igWeapons[i] != 0 && (i > 1 && i < 7)) {
                iWeaponSets[igTeam][igWeapons[i]]--;
            }
        }
            
        ResetPlayerWeapons(iPlayer);
        CPlayer::ShowWeaponMenu(iPlayer);
    }
    
    else if(playerData[iPlayer][isPlaying] == false) {
        SendClientMessage(playerid, C_RED, "* Error: The player is not playing in a base.");
        return true;
    }
    
    SendFormattedMessageToAll(C_GOLD, "* %s has shown the weaponmenu to %s.", CPlayer::getName(playerid), CPlayer::getName(iPlayer));
    return true;
}

cmd(setname, playerid, params[]) {
    if(playerData[playerid][level] < LEVEL_ADMIN) {
        return false;
    }
    
    new iPlayer,
        sNewName[MAX_PLAYER_NAME];
    
    if(sscanf(params, "us[20]", iPlayer, sNewName)) {
        SendClientMessage(playerid, C_RED, "* Syntax Error: '/setname <PlayerID/Name> <New Name>'");
        return true;
    }
    
    if(!IsPlayerConnected(playerid)) {
        SendClientMessage(playerid, C_RED, "* Error: This player is not connected.");
        return true;
    }
    
    new sQuery[128];
    format(sQuery, 128, "UPDATE players SET username = '%s' WHERE username = '%s'", sNewName, CPlayer::getName(iPlayer));
    mysql_query(sQuery);
    SendFormattedMessageToAll(C_ORANGE, "* %s is known as %s.", CPlayer::getName(iPlayer), sNewName);
    
    SetPlayerName(iPlayer, sNewName);
    return true;
}

cmd(add, playerid, params[]) {
    if(playerData[playerid][level] < LEVEL_MOD) 
    {
        return false;
    }
    
    if(gameData[bIsRoundActive] == false) 
    {
        SendClientMessage(playerid, C_RED, "* Error: There is no round active, thus you can't add a player.");
        return true;
    }
    
    new iPlayer,
        iHealth;
        
    if(sscanf(params, "ud", iPlayer, iHealth)) {
        SendClientMessage(playerid, C_RED, "* Syntax Error: '/add <PlayerID/Name> <Health (200 = full)>'");
        return true;
    }
    
    if(!IsPlayerConnected(iPlayer)) {
        SendClientMessage(playerid, C_RED, "* Error: Invalid player!");
        return true;
    }
    
    if(playerData[iPlayer][isPlaying] == true) {
        SendClientMessage(playerid, C_RED, "* Error: This player already plays.");
        return true;
    }
    
    SendFormattedMessageToAll(C_GOLD, "* %s added %s, with %d HP, to the round.", CPlayer::getName(playerid), CPlayer::getName(iPlayer), iHealth);
    
    if(playerData[iPlayer][team] == TEAM_HOME_SUB || playerData[iPlayer][team] == TEAM_AWAY_SUB)
    {
        CBase::addPlayer(iPlayer, true, float(iHealth));
    }
    
    else
    {
        CBase::addPlayer(iPlayer, false, float(iHealth));
    }
    
    return true;
}

cmd(remove, playerid, params[]) {
    if(playerData[playerid][level] < LEVEL_MOD) {
        return false;
    }
    
    if(gameData[bIsRoundActive] == false) {
        SendClientMessage(playerid, C_RED, "* Error: There is no round active, thus you can't remove a player.");
        return true;
    }
    
    new iPlayer;
    if(sscanf(params, "u", iPlayer)) {
        SendClientMessage(playerid, C_RED, "* Syntax Error: '/remove <PlayerID/Name>'");
        return true;
    }
    
    if(!IsPlayerConnected(iPlayer)) {
        SendClientMessage(playerid, C_RED, "* Error: Invalid player!");
        return true;
    }
    
    if(playerData[iPlayer][isPlaying] == false) {
        SendClientMessage(playerid, C_RED, "* Error: This player is not playing.");
        return true;
    }
    
    playerData[iPlayer][isPlaying] = false;
    CPlayer::SpawnEx(iPlayer);
    DisablePlayerCheckpoint(iPlayer);
    RemovePlayerMapIcon(iPlayer, BASE_ICON_ID);
    CBase::updateRestrictions(iPlayer);
    SendFormattedMessageToAll(C_GOLD, "* %s has removed %s from the round.", CPlayer::getName(playerid), CPlayer::getName(iPlayer));
    
    if(playerData[iPlayer][team] == TEAM_HOME) 
    {
        gameData[iPlayingHome]--;
        gameData[iTotalHome]--;
    }
            
    if(playerData[iPlayer][team] == TEAM_AWAY) 
    {
        gameData[iPlayingAway]--;
        gameData[iTotalAway]--;
    }
    
    CBase::CheckActivePlayers();
    return true;
}   

cmd(resetscores, playerid, params[]) {
    if(playerData[playerid][level] < LEVEL_MOD) {
        return false;
    }
    
    teamData[TEAM_HOME][iTeamScore] = 0;
    teamData[TEAM_AWAY][iTeamScore] = 0;
    SendFormattedMessageToAll(C_GOLD, "* %s has reset the team-scores.", CPlayer::getName(playerid));
    return true;
}

//=========================================//

//========= [Standard Commands] =========//
//=========================================//
cmd(commands, playerid, params[]) 
{
    SendClientMessage(playerid, C_LIGHTBLUE, "* Available commands: /kill | /gunmenu | /switch | /s(ync) | /spec | /specoff | /afk");
    SendClientMessage(playerid, C_LIGHTBLUE, "* /back | /mystats | /myweather | /mytime | /getstats | /me | /dm | /duel");
    SendClientMessage(playerid, C_LIGHTBLUE, "* /v(ehicle) | /weaponlist | /dmspawn | /exit | /viewbase | /scores | /teams");
    SendClientMessage(playerid, C_LIGHTBLUE, "* /pm | /dance");
    
    if(playerData[playerid][level] >= LEVEL_MOD) 
    {
        SendClientMessage(playerid, C_GREEN, "* Available moderator commands: /kick | /startbase | /endbase | /pausebase | /unpausebase");
        SendClientMessage(playerid, C_GREEN, "* /add | /remove | /give | /fsync | /fswitch | /fkill | /fspawn | /gethere | /goto | /sethealth");
        SendClientMessage(playerid, C_GREEN, "* /allvs | /balance | /resetscores | /heal | /explode | /slap | /fspawnall | /mute | /unmute");
        SendClientMessage(playerid, C_GREEN, "* /muteall | /unmuteall | /swap");
    }
    
    if(playerData[playerid][level] >= LEVEL_ADMIN) 
    {
        SendClientMessage(playerid, C_PINK, "* Available administrator commands: /ban | /setname | /config | /lockserver | /unlockserver");
        SendClientMessage(playerid, C_PINK, "* /unban");
    }
    
    if(playerData[playerid][level] >= LEVEL_MANAGEMENT) 
    {
        SendClientMessage(playerid, C_YELLOW, "* Available management commands: /jetpack");
        SendClientMessage(playerid, C_YELLOW, "* /base | /showbases | /hidebases | /createbase");
    }
    
    return true;
}

cmd(dance, playerid, params[])
{
    new iDance;
    
    if(sscanf(params, "d", iDance))
    {
        SendClientMessage(playerid, C_RED, "* Syntax Error: '/dance <1-4>'");
        return true;
    }
    
    if(iDance < 1 || iDance > 4)
    {
        SendClientMessage(playerid, C_RED, "* Syntax Error: '/dance <1-4>'");
        return true;
    }
    
    switch(iDance)
    {
        case 1: SetPlayerSpecialAction(playerid, SPECIAL_ACTION_DANCE1);
        case 2: SetPlayerSpecialAction(playerid, SPECIAL_ACTION_DANCE2);
        case 3: SetPlayerSpecialAction(playerid, SPECIAL_ACTION_DANCE3);
        case 4: SetPlayerSpecialAction(playerid, SPECIAL_ACTION_DANCE4);
    }
    
    SendFormattedMessage(playerid, C_PINK, "* Dance %d has been applied to your character.", iDance);
    return true;
}

cmd(admins, playerid, params[]) 
{
    new szOut[512], 
        szTemp[56], 
        iX;
        
    loop_players(i) 
    {
        if(playerData[playerid][level] >= LEVEL_MOD) 
        {
            format(szTemp, 56, "%s (%s)", CPlayer::getName(i), CPlayer::getLevelName(i));
            format(szOut, 512, "%s%s\n", szOut, szTemp);
            iX++;
        }
    }
    
    if(iX > 0) 
    {
        ShowPlayerDialog(playerid, DIALOG_ADMIN, DIALOG_STYLE_MSGBOX, "Online administrators", szOut, "Close", "");
        return true;
    }
    
    else 
    {
        SendClientMessage(playerid, C_RED, "* Error: There is no administrator online.");
        return true;
    }
}
        
cmd(kill, playerid, params[]) 
{
    SetPlayerHealth(playerid, 0.0);
    Admin("%s (%d) killed themself using '/kill'.", CPlayer::getName(playerid), playerid);
    return true;
}

cmd(pm, playerid, params[]) 
{
    new iPlayer,
        sMessage[128];
    
    if(sscanf(params, "us[128]", iPlayer, sMessage)) 
    {
        SendClientMessage(playerid, C_RED, "* Syntax Error: '/pm <PlayerID/Name> <Message>'");
        return true;
    }
    
    if(!IsPlayerConnected(iPlayer)) 
    {
        SendClientMessage(playerid, C_RED, "* Error: This player is not connected.");
        return true;
    }
    
    SendFormattedMessage(playerid, C_ORANGE, "Private message sent to %s (%d): %s", CPlayer::getName(iPlayer), iPlayer, sMessage);
    SendFormattedMessage(iPlayer, C_ORANGE, "Private message from %s (%d): %s", CPlayer::getName(playerid), playerid, sMessage);
    return true;
}
    
cmd(me, playerid, params[]) 
{
    new Action[128];
    if(sscanf(params, "s[32]", Action)) 
    {
        SendClientMessage(playerid, C_RED, "* Syntax Error: '/me <Action>'");
        return true;
    }
    
    SendFormattedMessageToAll(GetPlayerColor(playerid), "%s %s", CPlayer::getName(playerid), Action);
    return true;
}

cmd(readd, playerid, params[])
{
    new iPlayer;
    
    if(playerData[playerid][level] < LEVEL_MOD)
    {
        return false;
    }
    
    if(sscanf(params, "u", iPlayer))
    {
        SendClientMessage(playerid, C_RED, "* Syntax Error: '/readd <PlayerID/Name>'");
        return true;
    }
    
    if(gameData[bIsRoundActive] == false) 
    {
        SendClientMessage(playerid, C_RED, "* Error: There is no round active, thus you can't remove a player.");
        return true;
    }
    
    if(playerData[iPlayer][isPlaying] == false) 
    {
        SendClientMessage(playerid, C_RED, "* Error: This player is not playing.");
        return true;
    }
    
    playerData[iPlayer][isPlaying] = false;
    playerData[iPlayer][isReAdded] = false;
    CPlayer::SpawnEx(iPlayer);
    DisablePlayerCheckpoint(iPlayer);
    RemovePlayerMapIcon(iPlayer, BASE_ICON_ID);
    CBase::updateRestrictions(iPlayer);
    SendFormattedMessageToAll(C_GOLD, "* %s has removed %s from the round.", CPlayer::getName(playerid), CPlayer::getName(iPlayer));
    
    if(playerData[iPlayer][team] == TEAM_HOME) 
    {
        gameData[iPlayingHome]--;
        gameData[iTotalHome]--;
    }
            
    if(playerData[iPlayer][team] == TEAM_AWAY) 
    {
        gameData[iPlayingAway]--;
        gameData[iTotalAway]--;
    }
    
    return true;
}       
    
cmd(gunmenu, playerid, params[]) 
{
    if(playerData[playerid][isPlaying] == true && gameData[bWeaponChoose] == true) 
    {
        
        new igTeam = playerData[playerid][team],
            iAmmo,
            igWeapons[12];
                
        for(new i; i < 12; i++) 
        {
            GetPlayerWeaponData(playerid, i, igWeapons[i], iAmmo);
            if(igWeapons[i] != 0 && (i > 1 && i < 7)) 
            {
                iWeaponSets[igTeam][igWeapons[i]]--;
            }
        }
            
        ResetPlayerWeapons(playerid);
        CPlayer::ShowWeaponMenu(playerid);
    }
    
    else if(playerData[playerid][isPlaying] == false) 
    {
        SendClientMessage(playerid, C_RED, "* Error: You aren't playing in a base.");
        return true;
    }
    
    else if(gameData[bWeaponChoose] == false) 
    {
        SendClientMessage(playerid, C_RED, "* Error: It's too late to re-choose weapons.");
        return true;
    }
    
    return true;
}

cmd(switch, playerid, params[]) 
{
    new szFormatTeams[256];
    
    if(gameData[bIsRoundActive] == true && playerData[playerid][isPlaying] == true) 
    {
        SendClientMessage(playerid, C_RED, "* Error: You can't switch your team while the round is active, got it?");
        return true;
    }
    
    if(teamData[TEAM_HOME][bAttacking] == true) 
    {
        format(szFormatTeams, 256, "{FF3300}%s\n{80FFFE}%s\n{FFFF00}Referee\n{FF3300}%s SUB\n{80FFFE}%s SUB", gameConfig[homeName], gameConfig[awayName], gameConfig[homeName], gameConfig[awayName]);
    }
    
    else 
    {
        format(szFormatTeams, 256, "{80FFFE}%s\n{FF3300}%s\n{FFFF00}Referee\n{80FFFE}%s SUB\n{FF3300}%s SUB", gameConfig[homeName], gameConfig[awayName], gameConfig[homeName], gameConfig[awayName]);
    }
    
    ShowPlayerDialog(playerid, DIALOG_SWITCH, DIALOG_STYLE_LIST, "Choose a team", szFormatTeams, "Choose", "Quit");
    return true;
}

cmd(teams, playerid, params[]) 
{
    new iH,
        iA,
        iR,
        iSubH,
        iSubA;
        
    loop_players(i) 
    {
        switch(playerData[i][team])
        {
            case TEAM_HOME: iH++;
            case TEAM_HOME_SUB: iSubH++;
            case TEAM_AWAY: iA++;
            case TEAM_AWAY_SUB: iSubA++;
            case TEAM_REF: iR++;
        }
    }
    
    SendFormattedMessageToAll(C_GOLD, "* Teams | %s - %d (%d subs) / %s - %d (%d subs) | %d referees | %s", gameConfig[homeName], iH, iSubH, gameConfig[awayName], iA, iSubA, iR, CPlayer::getName(playerid));
    return true;
}

cmd(teamweather, playerid, params[]) {
    
    if(playerData[playerid][team] != TEAM_HOME && playerData[playerid][team] != TEAM_AWAY) {
        SendClientMessage(playerid, C_RED, "* Error: You can only change your team's weather while being in a team.");
        return true;
    }
    
    new iWeather;
    if(sscanf(params, "d", iWeather)) {
        SendClientMessage(playerid, C_RED, "* Syntax Error: '/teamweather <WeatherID>'");
        return true;
    }
    
    if(iWeather < 0 || iWeather > 45) {
        SendClientMessage(playerid, C_RED, "* Error: You may only choose weatherIDs between 0 and 45.");
        return true;
    }
    
    loop_players(i) {
        if(playerData[i][team] == playerData[playerid][team]) {
            SetPlayerWeather(i, iWeather);
        }
    }
    
    Team(playerData[playerid][team], "%s changed your team-weather to %d.", CPlayer::getName(playerid), iWeather);
    return true;
}

cmd(teamtime, playerid, params[]) {
    
    if(playerData[playerid][team] != TEAM_HOME && playerData[playerid][team] != TEAM_AWAY) {
        SendClientMessage(playerid, C_RED, "* Error: You can only change your team's time while being in a team.");
        return true;
    }
    
    new iTime;
    if(sscanf(params, "d", iTime)) {
        SendClientMessage(playerid, C_RED, "* Syntax Error: '/teamtime <0-23>'");
        return true;
    }
    
    if(iTime < 0 || iTime > 23) {
        SendClientMessage(playerid, C_RED, "* Syntax Error: '/teamtime <0-23>'");
        return true;
    }
    
    loop_players(i) {
        if(playerData[i][team] == playerData[playerid][team]) {
            SetPlayerTime(playerid, iTime, 0);
        }
    }
    
    Team(playerData[playerid][team], "%s changed your team-time to %d o'clock.", CPlayer::getName(playerid), iTime);
    return true;
}   

cmd(scores, playerid, params[]) {
    SendFormattedMessageToAll(C_GOLD, "* Team Scores | %s - %d / %s - %d | Round %d of %d | %s", gameConfig[homeName], teamData[TEAM_HOME][iTeamScore], gameConfig[awayName], teamData[TEAM_AWAY][iTeamScore], (teamData[TEAM_HOME][iTeamScore] + teamData[TEAM_AWAY][iTeamScore]), gameConfig[iMaxScore], CPlayer::getName(playerid)); 
    return true;
}       

cmd(sync, playerid, params[]) {

    if(playerData[playerid][isSyncSpawn] == true) 
    {
        SendClientMessage(playerid, C_RED, "* Error: You can't synchronize yourself now.");
        return true;
    }
    
    if(gameData[bIsPaused] == true)
    {
        SendClientMessage(playerid, C_RED, "* Error: Did you try to unfreeze yourself? Nice try!");
        return true;
    }
    
    SendClientMessage(playerid, C_YELLOW, "* You will be synchronized in 1 second...");
    SetTimerEx("alias_Sync", 1000, false, "d", playerid);
    return true;
}

cmd(s, playerid, params[]) return cmd_sync(playerid, params);

cmd(spec, playerid, params[])
{
    new iPlayer;
    if(sscanf(params, "u", iPlayer))
    {
        SendClientMessage(playerid, C_RED, "* Syntax Error: '/spec <PlayerID/Name>'");
        return true;
    }
    
    if(playerData[playerid][isPlaying] == true)
    {
        SendClientMessage(playerid, C_RED, "* Error: You cannot spectate someone while playing a base.");
        return true;
    }
    
    if(((playerData[iPlayer][team] == TEAM_HOME && (playerData[playerid][team] != TEAM_HOME && playerData[playerid][team] != TEAM_HOME_SUB)) || 
        (playerData[iPlayer][team] == TEAM_AWAY && (playerData[playerid][team] != TEAM_AWAY && playerData[playerid][team] != TEAM_AWAY_SUB)))
       && playerData[playerid][team] != TEAM_REF)
    {
        SendClientMessage(playerid, C_RED, "* Error: You can only spectate players being in your team.");
        return true;
    }
    
    if(!playerData[iPlayer][isPlaying])
    {
        SendClientMessage(playerid, C_RED, "* Error: This player is not playing right now.");
        return true;
    }
    
    if(playerData[playerid][spectateId] != INVALID_PLAYER_ID || playerData[playerid][isSpectating] == true)
    {
        CPlayer::Unspectate(playerid);
            
        SetTimerEx("alias_Spectate", 500, false, "ddb", playerid, iPlayer, true);
        SendFormattedMessage(playerid, C_PURPLE, "* You are now spectating %s.", CPlayer::getName(iPlayer));
        return true;
    }
    
    CPlayer::Spectate(playerid, iPlayer, true);
    SendFormattedMessage(playerid, C_PURPLE, "* You are now spectating %s.", CPlayer::getName(iPlayer));
    return true;
}

cmd(specoff, playerid, params[])
{
    if(playerData[playerid][spectateId] != INVALID_PLAYER_ID || playerData[playerid][isSpectating] == true)
    {
        SendClientMessage(playerid, C_PURPLE, "* You stopped spectating.");
        CPlayer::Unspectate(playerid);
    }
    
    else
    {
        SendClientMessage(playerid, C_RED, "* Error: You are not spectating anyone.");
    }
    
    return true;
}

cmd(afk, playerid, params[]) {
    new szReason[32];
    
    if(playerData[playerid][isAFK] == true) {
        SendClientMessage(playerid, C_RED, "* Error: You are already marked as AFK, use '/back' to play again.");
        return true;
    }
    
    sscanf(params, "S", szReason);
    playerData[playerid][isAFK] = true;
    if(strlen(szReason) > 0) {
        SendFormattedMessageToAll(C_ORANGE, "* %s is now AFK. (Reason: %s)", CPlayer::getName(playerid), szReason);
    }
    
    else {
        SendFormattedMessageToAll(C_ORANGE, "* %s is now AFK. (Reason: No reason given)", CPlayer::getName(playerid));
    }
    
    TogglePlayerControllable(playerid, false);
    return true;
}

cmd(back, playerid, params[]) {
    if(playerData[playerid][isAFK] == false) {
        SendClientMessage(playerid, C_RED, "* Error: You are not marked as AFK, use '/afk' to go AFK.");
        return true;
    }
    
    playerData[playerid][isAFK] = false;
    TogglePlayerControllable(playerid, true);
    SendFormattedMessageToAll(C_ORANGE, "* %s is now back.", CPlayer::getName(playerid));
    return true;
}

cmd(credits, playerid, params[]) {
    SendClientMessage(playerid, C_PINK, "* This gamemode was coded by {8CED15}thiaZ{E81CC9}! (2010-2012)");
    SendClientMessage(playerid, C_PINK, "* Thanks to {8CED15}Gaahl, Y_Less, Zeex, Incognito, Dracoblue, G-sTyLeZzZ, Slice and www.sa-mp.com{E81CC9}!");
    return true;
}   

cmd(mystats, playerid, params[]) {
    if(playerData[playerid][isLogged] == false) {
        return false;
    }
    
    new szFormat[512];
    
    format(szFormat, 512, "{FFFFFF}Statistics for player {0AE2FA}%s{FFFFFF},\n\n \
                            Adminlevel: {0AE2FA}%d\n \
                            {FFFFFF}Kills: {0AE2FA}%d\n \
                            {FFFFFF}Deaths: {0AE2FA}%d\n \
                            {FFFFFF}K/D Ratio: {0AE2FA}%.2f\n \
                            {FFFFFF}Bases played: {0AE2FA}%d\n \
                            {FFFFFF}Bases won: {0AE2FA}%d\n \
                            {FFFFFF}Bases lost: {0AE2FA}%d\n \
                            {FFFFFF}W/L Ratio: {0AE2FA}%.2f", CPlayer::getName(playerid),
                                                            CPlayer::getLevelName(playerid),
                                                            playerData[playerid][kills],
                                                            playerData[playerid][deaths],
                                                            getDiv(playerData[playerid][kills], playerData[playerid][deaths]),
                                                            (playerData[playerid][basesWon] + playerData[playerid][basesLost]),
                                                            playerData[playerid][basesWon],
                                                            playerData[playerid][basesLost],
                                                            getDiv(playerData[playerid][basesWon], playerData[playerid][basesLost]));
                                                            
    ShowPlayerDialog(playerid, DIALOG_MYSTATS, DIALOG_STYLE_MSGBOX, "Your statistics", szFormat, "OK", "");
    return true;
}

cmd(myweather, playerid, params[]) 
{
    new iWeather;
    
    if(sscanf(params, "d", iWeather)) 
    {
        SendClientMessage(playerid, C_RED, "* Syntax Error: '/myweather <WeatherID>'");
        return true;
    }
    
    if(iWeather < 0 || iWeather > 45) 
    {
        SendClientMessage(playerid, C_RED, "* Error: You may only choose weatherIDs between 0 and 45.");
        return true;
    }
    
    SetPlayerWeather(playerid, iWeather);
    SendFormattedMessage(playerid, C_PINK, "* You canged your weather to ID %d.", iWeather);
    Admin("%s changed his weather to ID %d.", CPlayer::getName(playerid), iWeather);
    return true;
}

cmd(mytime, playerid, params[]) 
{
    new iTime;
    
    if(sscanf(params, "d", iTime)) 
    {
        SendClientMessage(playerid, C_RED, "* Syntax Error: '/mytime <0-24>'");
        return true;
    }
    
    if(iTime < 0 || iTime > 24) 
    {
        SendClientMessage(playerid, C_RED, "* Error: You may only choose hours between 0 and 24 o'clock.");
        return true;
    }
    
    SetPlayerTime(playerid, iTime, 0);
    SendFormattedMessage(playerid, C_PINK, "* You canged your time %d o'clock.", iTime);
    Admin("%s changed his time to %d o'clock.", CPlayer::getName(playerid), iTime);
    return true;
}

cmd(getstats, playerid, params[]) 
{
    new iPlayer;
    
    if(sscanf(params, "u", iPlayer)) 
    {
        SendClientMessage(playerid, C_RED, "* Syntax Error: '/getstats <PlayerID/Name>'");
        return true;
    }
    
    if(!IsPlayerConnected(iPlayer)) 
    {
        SendClientMessage(playerid, C_RED, "* Error: Invalid player.");
        return true;
    }
    
    if(playerData[iPlayer][isLogged] == false) 
    {
        return false;
    }
    
    new szFormat[512];
    
    format(szFormat, 512, "{FFFFFF}Statistics for player {0AE2FA}%s{FFFFFF},\n\n \
                            Adminlevel: {0AE2FA}%d\n \
                            {FFFFFF}Kills: {0AE2FA}%d\n \
                            {FFFFFF}Deaths: {0AE2FA}%d\n \
                            {FFFFFF}K/D Ratio: {0AE2FA}%.2f\n \
                            {FFFFFF}Bases played: {0AE2FA}%d\n \
                            {FFFFFF}Bases won: {0AE2FA}%d\n \
                            {FFFFFF}Bases lost: {0AE2FA}%d\n \
                            {FFFFFF}W/L Ratio: {0AE2FA}%.2f", CPlayer::getName(iPlayer),
                                                            CPlayer::getLevelName(iPlayer),
                                                            playerData[iPlayer][kills],
                                                            playerData[iPlayer][deaths],
                                                            getDiv(playerData[iPlayer][kills], playerData[iPlayer][deaths]),
                                                            (playerData[iPlayer][basesWon] + playerData[iPlayer][basesLost]),
                                                            playerData[iPlayer][basesWon],
                                                            playerData[iPlayer][basesLost],
                                                            getDiv(playerData[iPlayer][basesWon], playerData[iPlayer][basesLost]));
                                                            
    ShowPlayerDialog(playerid, DIALOG_GETSTATS, DIALOG_STYLE_MSGBOX, "Statistics", szFormat, "OK", "");
    return true;
}

cmd(viewbase, playerid, params[]) 
{
    new iBase,
        szSpawn[16];
        
    if(sscanf(params, "ds", iBase, szSpawn)) 
    {
        SendClientMessage(playerid, C_RED, "* Syntax Error: '/viewbase <BaseID> <Att/Def/CP>");
        return true;
    }
    
    if(baseData[iBase][bIsValid] == false || iBase > MAX_BASES || iBase < 0) 
    {
        SendClientMessage(playerid, C_RED, "* Error: Invalid base.");
        return true;
    }
        
    
    if(!strcmp(szSpawn, "att", true)) 
    {
        SetPlayerInterior(playerid, baseData[iBase][iInterior]);
        SetPlayerPos(playerid, baseData[iBase][a_fX], baseData[iBase][a_fY], baseData[iBase][a_fZ]);
        SetPlayerFacingAngle(playerid, baseData[iBase][a_fA]);
        SendFormattedMessage(playerid, C_GREEN, "Viewing base #%d (%s). (Attacker spawn)", iBase, baseData[iBase][sDescription]);
        return true;
    }
    
    else if(!strcmp(szSpawn, "def", true)) 
    {
        SetPlayerInterior(playerid, baseData[iBase][iInterior]);
        SetPlayerPos(playerid, baseData[iBase][d_fX], baseData[iBase][d_fY], baseData[iBase][d_fZ]);
        SetPlayerFacingAngle(playerid, baseData[iBase][d_fA]);
        SendFormattedMessage(playerid, C_GREEN, "Viewing base #%d (%s). (Defender spawn)", iBase, baseData[iBase][sDescription]);
        return true;
    }
    
    else if(!strcmp(szSpawn, "cp", true)) 
    {
        SetPlayerInterior(playerid, baseData[iBase][iInterior]);
        SetPlayerPos(playerid, baseData[iBase][cp_fX], baseData[iBase][cp_fY], baseData[iBase][cp_fZ]);
        SendFormattedMessage(playerid, C_GREEN, "Viewing base #%d (%s). (Checkpoint)", iBase, baseData[iBase][sDescription]);
        return true;
    }
    
    else 
    {
        SendClientMessage(playerid, C_RED, "* Syntax Error: '/viewbase <BaseID> <Att/Def/CP>");
        return true;
    }
}
//=========================================//

//========= [Deathmatch Commands] =========//
//===========================================//
cmd(dm, playerid, params[]) {
    new iDM;
    if(sscanf(params, "d", iDM)) {
        SendClientMessage(playerid, C_RED, "* Syntax Error: '/dm <DeathmatchID>'");
        return true;
    }
    
    if(!CDM::isValidDM(iDM) || iDM > MAX_DMS || iDM < 0) {
        SendClientMessage(playerid, C_RED, "* Error: Invalid deathmatch.");
        return true;
    }
    
    CDM::playerSet(playerid, iDM);
    SendFormattedMessageToAll(C_YELLOW, "* %s has joined deathmatch %d (/dm %d | Weapons: %s & %s)", CPlayer::getName(playerid), iDM, iDM, getWeaponNameEx(dMData[iDM][idmWeapon][0]), getWeaponNameEx(dMData[iDM][idmWeapon][1])); 
    SendClientMessage(playerid, C_YELLOW, "* Kill your opponents! Use '/dmspawn' to re-spawn in this DM upon your next death.");
    SendClientMessage(playerid, C_YELLOW, "* Use '/exit' to quit the deathmatch.");
    return true;
}

cmd(dmspawn, playerid, params[]) 
{
    if(CDM::getPlayerDM(playerid) == -1) 
    {
        SendClientMessage(playerid, C_RED, "* Error: Join a deathmatch first!");
        return true;
    }
    
    playerData[playerid][isDMSpawn] = true;
    SendClientMessage(playerid, C_YELLOW, "* You'll spawn in the deathmatch now, use '/exit' to undo this.");
    return true;
}

cmd(exit, playerid, params[]) 
{
    if(CDM::getPlayerDM(playerid) == -1) 
    {
        SendClientMessage(playerid, C_RED, "* Error: Join a deathmatch first!");
        return true;
    }
    
    playerData[playerid][isDMSpawn] = false;
    playerData[playerid][activeDM] = -1;
    CPlayer::SpawnEx(playerid);
    SendClientMessage(playerid, C_YELLOW, "* You left the deathmatch.");
    return true;
}
//===========================================//

//========= [Spawn Commands] =========//
//======================================//
cmd(weaponlist, playerid, params[]) {
    SendClientMessage(playerid, C_CYAN, "=[{FFFF00}Full weapon list (Name - ID){33FF99}]=");
    for(new i; i < 40; i++) {
        if(isValidWeapon(i)) {
            SendFormattedMessage(playerid, C_CYAN, "[%s] [{FFFF00}%d{33FF99}]", getWeaponNameEx(i), i);
        }
    }
    
    return true;
}

cmd(vr, playerid, params[]) {
    if(playerData[playerid][isPlaying] == true) {
        SendClientMessage(playerid, C_RED, "* Error: You can't repair your vehicle while playing a base.");
        return true;
    }
    
    if(GetPlayerVirtualWorld(playerid) > 0 || GetPlayerInterior(playerid) > 0) {
        SendClientMessage(playerid, C_RED, "* Error: You can't repair your vehicle at the moment, sorry.");
        return true;
    }
    
    if(!IsPlayerInAnyVehicle(playerid)) {
        SendClientMessage(playerid, C_RED, "* Error: You have to be in a vehicle to repair it.");
        return true;
    }
    
    new iVehID = GetPlayerVehicleID(playerid);
    RepairVehicle(iVehID);
    SetVehicleHealth(iVehID, 1000.0);
    SendClientMessage(playerid, C_PINK, "* You just repaired your vehicle, have fun.");
    return true;
}

cmd(lobby, playerid, params[]) {
    if(GetPlayerVirtualWorld(playerid) > 0 || GetPlayerInterior(playerid) > 0) {
        SendClientMessage(playerid, C_RED, "* Error: You can't spawn in the lobby at the moment, sorry.");
        return true;
    }
    
    CPlayer::SpawnEx(playerid);
    return true;
}
        
cmd(v, playerid, params[]) 
{
    if(playerData[playerid][isPlaying] == false) 
    {
        SendClientMessage(playerid, C_RED, "* Error: You may only spawn vehicles while playing in a base.");
        return true;
    }
    
    if(!CPlayer::isAttacking(playerid)) 
    {
        SendClientMessage(playerid, C_RED, "* Error: Only attackers are allowed to spawn vehicles during a round.");
        return true;
    }
    
    if(GetPlayerInterior(playerid) > 0) 
    {
        SendClientMessage(playerid, C_RED, "* Error: You can't spawn any vehicle in an interior.");
        return true;
    }
        
    new iBase = gameData[iCurBase];
    if(!IsPlayerInRangeOfPoint(playerid, gameConfig[fCarSpawnDis], baseData[iBase][a_fX], baseData[iBase][a_fY], baseData[iBase][a_fZ]))
    {
        SendClientMessage(playerid, C_RED, "* Error: You can only spawn vehicles when you are in range of the attacker spawn.");
        return true;
    }
        
    if(playerData[playerid][spawnedVehicles] >= gameConfig[iCarSpawnMax]) 
    {
        SendClientMessage(playerid, C_RED, "* Error: You have reached the maximal car spawn limit.");
        return true;
    }
    
    new szTemp[60],
        iModel = -1;
        
    if(sscanf(params, "s[60]", szTemp)) 
    {
        SendClientMessage(playerid, C_RED, "* Syntax Error: '/v <VehicleID/Name>'");
        return true;
    }
    
    if(isNumeric(szTemp)) 
    {
        iModel = strval(szTemp);
    }
    
    else 
    {
        for(new i; i < sizeof(vehicleNames); i++) 
        {
            if(strfind(vehicleNames[i], szTemp, true) != -1) 
            {
                iModel = (i + 400);
                break;
            }
        }
    }
    
    if(!isValidVehicle(iModel)) 
    {
        SendClientMessage(playerid, C_RED, "* Error: Invalid/restricted vehicle model.");
        return true;
    }
    
    new iVeh,
        Float:X,
        Float:Y,
        Float:Z,
        Float:A;
    
    GetPlayerPos(playerid, X, Y, Z);
    GetPlayerFacingAngle(playerid, A);
        
    if(isCar(iModel)) 
    {
        new iRandom = random(sizeof(sexyVehicleColors)),
        iRandom2 = random(sizeof(vehicleRims));
        
        playerData[playerid][baseVehicleId] = CreateVehicle(iModel, X, Y, Z, A, sexyVehicleColors[iRandom], sexyVehicleColors[iRandom], 10000);
        iVeh = playerData[playerid][baseVehicleId];
        
        SetVehicleVirtualWorld(iVeh, BASE_WORLD);
        AddVehicleComponent(iVeh, 1010);
        AddVehicleComponent(iVeh, vehicleRims[iRandom2]);
        PutPlayerInVehicle(playerid, iVeh, 0);
    }
    
    else 
    {
        new iRandom = random(sizeof(sexyVehicleColors));
        
        playerData[playerid][baseVehicleId] = CreateVehicle(iModel, X, Y, Z, A, sexyVehicleColors[iRandom], sexyVehicleColors[iRandom], 10000);
        iVeh = playerData[playerid][baseVehicleId];
        
        SetVehicleVirtualWorld(iVeh, BASE_WORLD);
        PutPlayerInVehicle(playerid, iVeh, 0);
    }
    
    Iter_Add(Vehicle, iVeh);
    vehicleData[iVeh][VehicleHealth] = Create3DTextLabel("Initializing...", C_RED, 0.0, 0.0, 0.0, 30.0, 1, true);
    Attach3DTextLabelToVehicle(vehicleData[iVeh][VehicleHealth], iVeh, 0.0, 0.0, 0.7);
    
    playerData[playerid][spawnedVehicles]++;
    SendFormattedMessage(playerid, C_LIGHTBLUE, "* You just spawned a(n) %s (Model ID: %d | HP: 1000 / 1000 | Vehicle %d of %d)", vehicleNames[(iModel - 400)], iModel, playerData[playerid][spawnedVehicles], gameConfig[iCarSpawnMax]);
    return true;
}
        
cmd(car, playerid, params[]) return cmd_v(playerid, params);
cmd(veh, playerid, params[]) return cmd_v(playerid, params);
cmd(vehicle, playerid, params[]) return cmd_v(playerid, params);

cmd(startbase, playerid, params[]) 
{
    #if !DEBUG
    if(playerData[playerid][level] < LEVEL_MOD) {
        return false;
    }

    new iA,
        iH;
        
    loop_players(i)
    {
        if(playerData[i][team] == TEAM_HOME)
        {
            iH++;
        }
    
        else if(playerData[i][team] == TEAM_AWAY)
        {
            iA++;
        }
    }
    
    if(iH < 2 || iA < 2)
    {
        SendClientMessage(playerid, C_RED, "* Error: At least 2 players have to be in each team to start a base.");
        return true;
    }
    #endif
        
    new iBaseID;
    if(sscanf(params, "d", iBaseID)) 
    {
        SendClientMessage(playerid, C_RED, "* Syntax Error: '/startbase <BaseID>'");
        return true;
    }
    
    if(iBaseID == -1) 
    {
        new iRandomBase = Iter_Random(Bases);
        
        hookIRC("onGameStart", "ii", 1, iRandomBase);
        CBase::prepareBase(iRandomBase, true);
        SendFormattedMessageToAll(C_GOLD, "* %s has started a random base.", CPlayer::getName(playerid));
        SendFormattedMessageToAll(C_GOLD, "* (BaseID: %d | Description: %s | Played: %d | Attacker Wins: %d | Defender Wins: %d)", iRandomBase, baseData[iRandomBase][sDescription], baseData[iRandomBase][iPlayed], baseData[iRandomBase][iAttWins], baseData[iRandomBase][iDefWins]);
        return true;
    }
    
    else if(iBaseID == -2) 
    {
        new iRandomBase = Iter_Random(IntBases);
        
        hookIRC("onGameStart", "ii", 1, iRandomBase);
        CBase::prepareBase(iRandomBase, true);
        SendFormattedMessageToAll(C_GOLD, "* %s has started a random interior base.", CPlayer::getName(playerid));
        SendFormattedMessageToAll(C_GOLD, "* (BaseID: %d | Description: %s | Played: %d | Attacker Wins: %d | Defender Wins: %d)", iRandomBase, baseData[iRandomBase][sDescription], baseData[iRandomBase][iPlayed], baseData[iRandomBase][iAttWins], baseData[iRandomBase][iDefWins]);
        return true;
    }
    
    else if(iBaseID == -3) 
    {
        new iBase = gameData [iCurBase];
        
        if(iBase == -1) 
        {
            SendClientMessage(playerid, C_RED, "* Error: There is no BaseID saved, '/startbase -3' doesn't work at the moment.");
            return true;
        }
        
        hookIRC("onGameStart", "ii", 1, iBase);
        CBase::prepareBase(iBase, true);
        SendFormattedMessageToAll(C_GOLD, "* %s has started the previous base.", CPlayer::getName(playerid));
        SendFormattedMessageToAll(C_GOLD, "* (BaseID: %d | Description: %s | Played: %d | Attacker Wins: %d | Defender Wins: %d)", iBase, baseData[iBase][sDescription], baseData[iBase][iPlayed], baseData[iBase][iAttWins], baseData[iBase][iDefWins]);
        return true;
    }
    
    else 
    {
        if(baseData[iBaseID][bIsValid] == false) 
        {
            SendClientMessage(playerid, C_RED, "* Error: Invalid base ID.");
            return true;
        }
            
        hookIRC("onGameStart", "ii", 1, iBaseID);
        CBase::prepareBase(iBaseID, true);
        SendFormattedMessageToAll(C_GOLD, "* %s has started a base.", CPlayer::getName(playerid));
        SendFormattedMessageToAll(C_GOLD, "* (BaseID: %d | Description: %s | Played: %d | Attacker Wins: %d | Defender Wins: %d)", iBaseID, baseData[iBaseID][sDescription], baseData[iBaseID][iPlayed], baseData[iBaseID][iAttWins], baseData[iBaseID][iDefWins]);
        return true;
    }   
}

cmd(startarena, playerid, params[]) 
{
    #if !DEBUG
    if(playerData[playerid][level] < LEVEL_MOD) 
    {
        return false;
    }

    new iA,
        iH;
        
    loop_players(i)
    {
        if(playerData[i][team] == TEAM_HOME)
        {
            iH++;
        }
    
        else if(playerData[i][team] == TEAM_AWAY)
        {
            iA++;
        }
    }
    
    if(iH < 2 || iA < 2)
    {
        SendClientMessage(playerid, C_RED, "* Error: At least 2 players have to be in every team to start a base.");
        return true;
    }
    #endif
      
    new iArena;
    if(sscanf(params, "d", iArena)) 
    {
        SendClientMessage(playerid, C_RED, "* Syntax Error: '/startarena <ArenaID>'");
        return true;
    }
    
    if(iArena == -1) 
    {
        new iRandomArena = Iter_Random(Arenas);
        
        hookIRC("onGameStart", "ii", 0, iRandomArena);
        CArena::prepareArena(iRandomArena, true);
        SendFormattedMessageToAll(C_GOLD, "* %s has started a random arena.", CPlayer::getName(playerid));
        SendFormattedMessageToAll(C_GOLD, "* (ArenaID: %d)", iRandomArena);
        return true;
    }
    
    if(iArena == -2) 
    {
        new iRandomArena = Iter_Random(IntArenas);
        
        hookIRC("onGameStart", "ii", 0, iRandomArena);
        CBase::prepareBase(iRandomArena, true);
        SendFormattedMessageToAll(C_GOLD, "* %s has started a random interior arena.", CPlayer::getName(playerid));
        SendFormattedMessageToAll(C_GOLD, "* (ArenaID: %d)", iRandomArena);
        return true;
    }
    
    else if(iArena >= 0)
    {
        if(arenaData[iArena][bIsValid] == false) 
        {
            SendClientMessage(playerid, C_RED, "* Error: Invalid arena ID.");
            return true;
        }
            
        hookIRC("onGameStart", "ii", 0, iArena);
        CArena::prepareArena(iArena, true);
        SendFormattedMessageToAll(C_GOLD, "* %s has started an arena.", CPlayer::getName(playerid));
        SendFormattedMessageToAll(C_GOLD, "* (ArenaID: %d)", iArena);
        return true;
    }

    else
    {
        SendClientMessage(playerid, C_RED, "* Syntax Error: '/startarena <ArenaID>'");
        return true;
    }
}

cmd(endarena, playerid, params[]) 
{
    if(playerData[playerid][level] < LEVEL_MOD) 
    {
        return false;
    }
    
    if(!gameData[bIsRoundActive] || !gameData[bIsArena]) 
    {
        SendClientMessage(playerid, C_RED, "* Error: There is no active arena.");
        return true;
    }
    
    CArena::endArena(CASE_ADMINEND);
    SendFormattedMessageToAll(C_GOLD, "%s has stopped the arena.", CPlayer::getName(playerid));
    return true;
}

cmd(endbase, playerid, params[]) 
{
    if(playerData[playerid][level] < LEVEL_MOD) 
    {
        return false;
    }
    
    if(!gameData[bIsRoundActive] || gameData[bIsArena]) 
    {
        SendClientMessage(playerid, C_RED, "* Error: There is no active base.");
        return true;
    }
    
    CBase::EndBase(CASE_ADMINEND);
    SendFormattedMessageToAll(C_GOLD, "%s has stopped the base.", CPlayer::getName(playerid));
    return true;
}

cmd(allvs, playerid, params[]) {
    if( playerData[playerid][level] < LEVEL_MOD) {
        return false;
    }
    
    if(gameData[bIsRoundActive] == true) {
        SendClientMessage(playerid, C_RED, "* Error: You can't change the teams while a round is active.");
        return true;
    }
    
    new szTag[32];
    if(sscanf(params, "s", szTag)) 
    {
        SendClientMessage(playerid, C_RED, "* Syntax Error: '/allvs <ClanTag>'");
        return true;
    }
    
    loop_players(i) 
    {
        if(playerData[i][team] == TEAM_REF) 
        {
            continue;
        }
        
        if(playerData[i][isSpawned] == false) 
        {
            continue;
        }
        
        if(strfind(CPlayer::getName(i), szTag, true) != -1) 
        {
            CPlayer::crashSafeSkinSync(i, gameConfig[teamSkin][TEAM_HOME]);
            
            playerData[i][team] = TEAM_HOME;
            CPlayer::UpdatePlayerColor(i);
        }
        
        else 
        {
            CPlayer::crashSafeSkinSync(i, gameConfig[teamSkin][TEAM_AWAY]);
            
            playerData[i][team] = TEAM_AWAY;
            CPlayer::UpdatePlayerColor(i);
        }
    }
    
    SendFormattedMessageToAll(C_GOLD, "* %s set everyone with '%s' in their name to team Home.", CPlayer::getName(playerid), szTag);
    return true;
}

cmd(lockserver, playerid, params[])
{
    if(playerData[playerid][level] < LEVEL_ADMIN) 
    {
        return false;
    }
    
    new szPW[32],
        szPreRCON[64];
    if(sscanf(params, "s[32]", szPW)) 
    {
        SendClientMessage(playerid, C_RED, "* Syntax Error: '/lockserver <Password>'");
        return true;
    }
    
    format(szPreRCON, 64, "password %s", szPW);
    SendRconCommand(szPreRCON);
    
    SendFormattedMessageToAll(C_GOLD, "* %s has locked the server. (%s)", CPlayer::getName(playerid), szPW);
    return true;
}

cmd(unlockserver, playerid, params[])
{
    if(playerData[playerid][level] < LEVEL_ADMIN) 
    {
        return false;
    }
   
    SendRconCommand("password 0");
    SendFormattedMessageToAll(C_GOLD, "* %s has unlocked the server.", CPlayer::getName(playerid));
    return true;
}
    
cmd(balance, playerid, params[]) 
{
    if(playerData[playerid][level] < LEVEL_MOD) 
    {
        return false;
    }
    
    if(gameData[bIsRoundActive] == true) 
    {
        SendClientMessage(playerid, C_RED, "* Error: You can't change the teams while a round is active.");
        return true;
    }
    
    new iT = random(2);
    new bool:bFirst = true;
    
    loop_players(i) 
    {
        if(playerData[i][team] == TEAM_REF) 
        {
            continue;
        }
        
        if(playerData[i][isSpawned] == false) 
        {
            continue;
        }
        
        if(bFirst == true) 
        {
            CPlayer::crashSafeSkinSync(i, gameConfig[teamSkin][iT]);
            
            playerData[i][team] = iT;
            CPlayer::UpdatePlayerColor(i);
            bFirst = false;
        }
        
        else 
        {
            if(iT == TEAM_HOME) 
            {
                iT = TEAM_AWAY;
            }
            
            else 
            {
                iT = TEAM_HOME;
            }
            
            CPlayer::crashSafeSkinSync(i, gameConfig[teamSkin][iT]);
            
            playerData[i][team] = iT;
            CPlayer::UpdatePlayerColor(i);
        }
    }
        
    SendFormattedMessageToAll(C_GOLD, "* %s has balanced the teams.", CPlayer::getName(playerid));
    return true;
}
        
    

cmd(pausebase, playerid, params[]) 
{
    if( playerData[playerid][level] < LEVEL_MOD) 
    {
        return false;
    }
    
    if(gameData[bIsRoundActive] == false) 
    {
        SendClientMessage(playerid, C_RED, "* Error: There is no base active at the moment.");
        return true;
    }
    
    if(gameData[bIsPaused] == true) 
    {
        SendClientMessage(playerid, C_RED, "* Error: The round is already paused.");
    }
    
    gameData[bIsPaused] = true;
    SendFormattedMessageToAll(C_GOLD, "* %s has paused the base.", CPlayer::getName(playerid));
    GameTextForAll("~p~The game has been paused.", 1500, 5);
    
    loop_players(i) 
    {
        if(playerData[i][isPlaying] == true) 
        {
            TogglePlayerControllable(i, false);
        }
    }
    
    return true;
}

cmd(unpausebase, playerid, params[]) 
{
    if( playerData[playerid][level] < LEVEL_MOD) 
    {
        return false;
    }
    
    if(gameData[bIsRoundActive] == false) 
    {
        SendClientMessage(playerid, C_RED, "* Error: There is no base active at the moment.");
        return true;
    }
    
    if(gameData[bIsPaused] == false) 
    {
        SendClientMessage(playerid, C_RED, "* Error: The round is not paused.");
    }
    
    SendFormattedMessageToAll(C_GOLD, "* %s has unpaused the base.", CPlayer::getName(playerid));
    alias_Unpause(0);   
    return true;
}

cmd(duel, playerid, params[]) {
    new sAction[64],
        sParams[64];
    if(sscanf(params, "s[32]S", sAction, sParams)) {
        SendClientMessage(playerid, C_RED, "* Syntax Error: '/duel <Invite/Accept/Leave/Info/Spec/StopSpec>'");
        return true;
    }
    
    if(!strcmp(sAction, "invite", true)) {
        if(duelData[bIsRunning] == true) {
            SendClientMessage(playerid, C_RED, "* Error: Duel is already running.");
            return true;
        }
        
        new iPlayer,
            iWeapon[2];
        if(sscanf(sParams, "udd", iPlayer, iWeapon[0], iWeapon[1])) {
            SendClientMessage(playerid, C_RED, "* Syntax Error: '/duel invite <PlayerID/Name> <WeaponID 1> <WeaponID 2>'");
            SendClientMessage(playerid, C_RED, "* Use '/weaponlist' to get the weapon IDs.");
            return true;
        }
        
        if(!IsPlayerConnected(iPlayer) || playerid == iPlayer) {
            SendClientMessage(playerid, C_RED, "* Invalid player.");
            return true;
        }
        
        if(!isValidWeapon(iWeapon[0]) || !isValidWeapon(iWeapon[1])) {
            SendClientMessage(playerid, C_RED, "* Invalid weapon id(s).");
            SendClientMessage(playerid, C_RED, "* Use '/weaponlist' to get the weapon IDs.");
            return true;
        }
        
        SendFormattedMessage(iPlayer, C_BLUE, "* %s wants to duel you! (Rounds: 3 | Weapons: %s & %s)", CPlayer::getName(playerid), getWeaponNameEx(iWeapon[0]), getWeaponNameEx(iWeapon[1]));
        SendClientMessage(iPlayer, C_BLUE, "* Type '/duel accept' in the next 30 seconds to fight!");
        
        SendFormattedMessage(playerid, C_BLUE, "* %s has been invited into a duel! (Rounds: 3 | Weapons: %s & %s)", CPlayer::getName(iPlayer), getWeaponNameEx(iWeapon[0]), getWeaponNameEx(iWeapon[1]));
        
        duelData[iPlayerID][0] = playerid;
        duelData[iPlayerID][1] = iPlayer;
        duelData[iWeapons][0] = iWeapon[0];
        duelData[iWeapons][1] = iWeapon[1];
        duelData[bIsRunning] = false;
        
        playerData[playerid][isDuel] = true;
        playerData[iPlayer][isDuel] = true;
        
        duelData[iDuelTimer] = SetTimerEx("alias_FreeDuel", 30000, false, "b", true);
        return true;
    }
    
    else if(!strcmp(sAction, "accept", true)) {
        if(playerid != duelData[iPlayerID][1]) {
            SendClientMessage(playerid, C_RED, "* Error: You haven't been invited to a duel.");
            return true;
        }
        
        if(!IsPlayerConnected(duelData[iPlayerID][0])) {
            SendClientMessage(playerid, C_RED, "* Error: Your opponent left the server.");
            CDuel::FreeDuel(true);
            KillTimer(duelData[iDuelTimer]);
            return true;
        }
        
        SendFormattedMessageToAll(C_BLUE, "Initializing duel: %s vs. %s (Rounds: 3 | Weapons: %s & %s)", CPlayer::getName(duelData[iPlayerID][0]), CPlayer::getName(duelData[iPlayerID][1]), getWeaponNameEx(duelData[iWeapons][0]), getWeaponNameEx(duelData[iWeapons][1]));
        duelData[bIsRunning] = true;
        KillTimer(duelData[iDuelTimer]);
        duelData[iDuelCount] = 4;
        CDuel::DuelCount();
        return true;
    }
    
    else if(!strcmp(sAction, "leave", true)) {
        if(playerid != duelData[iPlayerID][0] && playerid != duelData[iPlayerID][1]) {
            SendClientMessage(playerid, C_RED, "* Error: You are not fighting in a duel.");
            return true;
        }
        
        if(playerid == duelData[iPlayerID][0]) {
            SendFormattedMessageToAll(C_BLUE, "* %s has left the duel, %s has won.", CPlayer::getName(playerid), CPlayer::getName(duelData[iPlayerID][1]));
            
            playerData[playerid][isDuel] = false;
            playerData[duelData[iPlayerID][1]][isDuel] = false;
            CPlayer::SpawnEx(duelData[iPlayerID][0]);
            CDuel::EndDuel(duelData[iPlayerID][1]);
        }
        
        if(playerid == duelData[iPlayerID][1]) {
            SendFormattedMessageToAll(C_BLUE, "* %s has left the duel, %s has won.", CPlayer::getName(playerid), CPlayer::getName(duelData[iPlayerID][0]));
            
            playerData[playerid][isDuel] = false;
            playerData[duelData[iPlayerID][0]][isDuel] = false;
            CPlayer::SpawnEx(duelData[iPlayerID][1]);
            CDuel::EndDuel(duelData[iPlayerID][0]);
        }
        
        return true;
    }
    
    else if(!strcmp(sAction, "info", true)) {
        if(duelData[bIsRunning] == false) {
            SendClientMessage(playerid, C_RED, "* Error: There is no duel running at the moment.");
            return true;
        }
        
        SendFormattedMessage(playerid, C_BLUE, "[Duel Status] %s vs. %s (%d - %d)", CPlayer::getName(duelData[iPlayerID][0]),  CPlayer::getName(duelData[iPlayerID][1]), duelData[iScore][0], duelData[iScore][0]);
        return true;
    }
    
    else if(!strcmp(sAction, "spec", true)) {
        if(duelData[bIsRunning] == false) {
            SendClientMessage(playerid, C_RED, "* Error: There is no duel running at the moment.");
            return true;
        }
        
        if(GetPlayerVirtualWorld(playerid) > 0 || GetPlayerInterior(playerid) > 0) {
            SendClientMessage(playerid, C_RED, "* Error: You can't spectate the duel while being in a virtual world/interior.");
            return true;
        }
        
        SetPlayerPos(playerid, duelPos[2][d_X], duelPos[2][d_Y], duelPos[2][d_Z] + 3);
        SetPlayerVirtualWorld(playerid, 2);
        SendClientMessage(playerid, C_BLUE, "* You are now spectating the duel. Use '/duel stopspec' to play again.");
        Admin("%s is now spectating the duel.", CPlayer::getName(playerid));
        playerData[playerid][isSpectatingDuel] = true;
        return true;
    }
    
    if(!strcmp(sAction, "stopspec", true)) {
        if(playerData[playerid][isSpectatingDuel] == false) {
            SendClientMessage(playerid, C_RED, "* Error: You are not spectating the duel.");
            return true;
        }
        
        SetCameraBehindPlayer(playerid);
        CPlayer::SpawnEx(playerid);
        playerData[playerid][isSpectatingDuel] = false;
        return true;
    }
    
    else {
        SendClientMessage(playerid, C_RED, "* Syntax Error: '/duel <Invite/Accept/Leave/Info/Spec/StopSpec>'");
        return true;
    }
}